package nz.ac.vuw.ecs.kcassell.personcars;

import java.util.logging.Logger;

/**
 * This class has characteristics of both a Person and a Car. ToString,
 * hashCode, equals, and a constructor accesses both Person and Car fields. Most
 * methods access fields directly.
 * 
 * @author Keith
 */

public class PersonCarSpecial {
	// Person fields
	private String firstName;
	private String lastName;
	private int id;

	// Car fields
	private String make;
	private String model;

	/** The vehicle id number */
	private int vin;

	private final Logger logger = Logger.getLogger(this.getClass()
			.getSimpleName());

	public String getFirstName() {
		logger.entering("PersonCarSpecial", "getFirstName");
		return firstName;
	}

	public void setFirstName(String firstName) {
		logger.entering("PersonCarSpecial", "setFirstName");
		this.firstName = firstName;
	}

	public String getLastName() {
		logger.entering("PersonCarSpecial", "getLastName");
		return lastName;
	}

	public void setLastName(String surname) {
		logger.entering("PersonCarSpecial", "setLastName");
		this.lastName = surname;
	}

	public int getId() {
		logger.entering("PersonCarSpecial", "getId");
		return id;
	}

	public void setId(int id) {
		logger.entering("PersonCarSpecial", "setId");
		this.id = id;
	}

	public String getMake() {
		logger.entering("PersonCarSpecial", "getMake");
		return make;
	}

	public void setMake(String make) {
		logger.entering("PersonCarSpecial", "setMake");
		this.make = make;
	}

	public String getModel() {
		logger.entering("PersonCarSpecial", "getModel");
		return model;
	}

	public void setModel(String model) {
		logger.entering("PersonCarSpecial", "setModel");
		this.model = model;
	}

	public int getVin() {
		logger.entering("PersonCarSpecial", "getVin");
		return vin;
	}

	public void setVin(int vin) {
		logger.entering("PersonCarSpecial", "setVin");
		this.vin = vin;
	}

	public String getPersonInfo() {
		return "" + id + ": " + firstName + " " + lastName;
	}

	public String getPersonName() {
		return firstName + " " + lastName;
	}

	public String getCarInfo() {
		return "" + vin + ": " + make + " " + model;
	}

	public String getCarDescription() {
		return make + " " + model;
	}

	public String toString() {
		return getPersonInfo() + " owns a " + getCarInfo();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());
		result = prime * result + id;
		result = prime * result
				+ ((lastName == null) ? 0 : lastName.hashCode());
		result = prime * result + ((make == null) ? 0 : make.hashCode());
		result = prime * result + ((model == null) ? 0 : model.hashCode());
		result = prime * result + vin;
		return result;
	}

	/**
	 * @param firstName
	 * @param lastName
	 * @param id
	 * @param make
	 * @param model
	 * @param vin
	 */
	public PersonCarSpecial(String firstName, String lastName, int id,
			String make, String model, int vin) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.id = id;
		this.make = make;
		this.model = model;
		this.vin = vin;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PersonCarSpecial other = (PersonCarSpecial) obj;
		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;
		if (id != other.id)
			return false;
		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;
		if (make == null) {
			if (other.make != null)
				return false;
		} else if (!make.equals(other.make))
			return false;
		if (model == null) {
			if (other.model != null)
				return false;
		} else if (!model.equals(other.model))
			return false;
		if (vin != other.vin)
			return false;
		return true;
	}

}
